const codeCollection = require("../models/codeCollection")

var express = require('express');
var router = express.Router();

const formidable = require('formidable');

//返回图片
router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
          codeCollection.create({
            UUID: fields.UUID,
            pointId: fields.pointId,
            demoId: fields.demoId,
            codeDemoId: fields.codeDemoId,     // 代码练习 id ，教程示例中的
            js: fields.js,
            css: fields.css,
            html: fields.html,
            title: fields.title,          // 案例本身标题
            des: fields.des,            // 自定义的本条收藏的标题
            time: fields.time            // 收藏时间
          }, (error, doc) => {
            // console.log(doc)
              if (error) {
                  res.json({ 'state': false, 'msg': error });
              } else {
                  res.json({ 'state': true, 'msg': 'ok' });
              }
          })

        }

    });

});

module.exports = router;